using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BHXH.Core.Domain;
using BHXH.Core.IService;
using FX.Data;
using NHibernate;

namespace BHXH.Core.ServiceImp
{
    public class hs_A01aTS_dtService: BaseService<hs_A01aTS_dt ,int>,Ihs_A01aTS_dtService
    {
        static ISession mySession;
        public hs_A01aTS_dtService(string sessionFactoryConfigPath)
            : base(sessionFactoryConfigPath)
        {}

        public IList<hs_A01aTS_dt> layTatCahs_01adt()
        {
            var a = GetAll();
            return a;
        }

        public int Update_hs_01adt(hs_A01aTS_dt hs)
        {
            hs_A01aTS_dt hsnew = new hs_A01aTS_dt();
            hsnew = hs;
            using (mySession = this.NHibernateSession.SessionFactory.OpenSession())
            {
                int a = mySession.CreateQuery("Update hs_A01aTS_dt set CT01 =:ct01,CT02 =:ct02,QuocTich=:quoctich" +
                    ",CT04 =:ct04,CT05 =:ct05,CT06 =:ct06,Loai=:loai,CT08 =:ct08,CT09 =:ct09,CT10 =:ct10"+
                    ",CT11 =:ct11,CT12 =:ct12,CT13 =:ct13,CT14 =:ct14,CT15 =:ct15,CT16 =:ct16,MaPB =:mapb where ID =:id")
                    .SetParameter("ct01", hs.CT01)
                    .SetParameter("ct02", hs.CT02)
                    .SetParameter("quoctich", hs.QuocTich)
                    .SetParameter("ct04", hs.CT04)
                    .SetParameter("ct05", hs.CT05)
                    .SetParameter("ct06", hs.CT06)
                    .SetParameter("loai", hs.Loai)
                    .SetParameter("ct08", hs.CT08)
                    .SetParameter("ct09", hs.CT09)
                    .SetParameter("ct10", hs.CT10)
                    .SetParameter("ct11", hs.CT11)
                    .SetParameter("ct12", hs.CT12)
                    .SetParameter("ct13", hs.CT13)
                    .SetParameter("ct14", hs.CT14)
                    .SetParameter("ct15", hs.CT15)
                    .SetParameter("ct16", hs.CT16)
                    .SetParameter("mapb", hs.MaPB)
                    .SetParameter("id", hs.ID)
                    .ExecuteUpdate();
                CommitChanges();
                mySession.Clear();
                return a;                
            }
        }

        public bool Add_hs_01adt(hs_A01aTS_dt hs)
        {

            using (mySession = this.NHibernateSession.SessionFactory.OpenSession())
            {
                mySession.Save(hs);
                mySession.Flush();
                return true;
            }
        }
    
        public int Delete_hs_01adt(string ID)
        {
            using (mySession = this.NHibernateSession.SessionFactory.OpenSession())
            {
                int a = mySession.CreateQuery("DELETE FROM hs_A01aTS_dt hs WHERE hs.ID=:id")                    
                    .SetParameter("id", int.Parse(ID))
                    .ExecuteUpdate();
                CommitChanges();
                mySession.Clear();
                return a;
            }
        }
    }

}